package model

import (
	"gorm.io/gorm"
	"user-server/basic/config"
)

type User struct {
	gorm.Model
	Username string `gorm:"type:varchar(20)" json:"username" binding:"required"`
	Password string `gorm:"type:varchar(32)" json:"password" binding:"required"`
	Mobile   string `gorm:"type:char(11)" json:"mobile" binding:"required"`
	Email    string `gorm:"type:varchar(100)" json:"email" binding:"required"`
}

type MemberPackage struct {
	gorm.Model
	Name     string  `gorm:"type:varchar(20)" json:"name" binding:"required"`
	Price    float64 `gorm:"type:decimal(10,2)" json:"price" binding:"required"`
	Duration string  `gorm:"type:varchar(100)" json:"duration" binding:"required"`
}

func (m *MemberPackage) CreateMemberPackage() error {
	return config.DB.Create(&m).Error
}

type RechargeOrder struct {
	gorm.Model
	UserId    int     `gorm:"type:int" json:"user_id" binding:"required"`
	PackageId int     `gorm:"type:int" json:"package_id" binding:"required"`
	Amount    float64 `gorm:"type:decimal(10,2)" json:"amount" binding:"required"`
	PayStatus int     `gorm:"type:int" json:"pay_status" binding:"required"`
}

func (r *RechargeOrder) CreateRechargeOrder() error {
	return config.DB.Create(&r).Error
}

type ViewingPermission struct {
	gorm.Model
	UserId    int `gorm:"type:varchar(20)" json:"user_id" binding:"required"`
	PackageId int `gorm:"type:varchar(20)" json:"package_id" binding:"required"`
	Status    int `gorm:"type:int" json:"status" binding:"required"`
}

func (v *ViewingPermission) CreateViewingPermission() error {
	return config.DB.Create(&v).Error
}
